﻿
namespace TOPTECH.Labs.OpenClosed.Expert
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    public static class Helper
    {
        public static IList<T> GetObjectsFor<T>()
        {
            Type strategyType = typeof(T);

            // Listet alle Typen auf, die in diesem Projekt existieren, die das Interface
            // T implementieren 
            List<Type> types = AppDomain.CurrentDomain.GetAssemblies()
                              .SelectMany(s => s.GetTypes())
                              .Where(p => strategyType.IsAssignableFrom(p) && p.IsClass).ToList();

            return types.Select(type => (T)Activator.CreateInstance(type)).ToList();
        }
    }
}
